mmap confusion

mmap confusion

am 20.09.2010 07:33:05 von Rajat Jain

Hello List,

I wanted to understand how the mmap works. I mean, not from the kernel APIs or data structures perspective, but from the HW perspective. I understand that the use case is this: typically applications will mmap() a file (a device file or any other file) into user space, and then use direct pointers to read / write to that file. So as I understand, after the call to mmap, the compiler will generate simple load and store instructions fo any reads / writes into that file. What I'm trying to understand is that how is it ensured that those load & store instructions get translated into file reads/ writes. I think there are two cases:

1) If the backing file is /dev/mem or a device file, then at the time of mmap(), the page table entries / TLB entries are set up such that the virtual address in the user space, maps to the actual physical address desired. And the thus job is done. This case is clear.

2) The other case is that when the file is actually a datafile present in a file system lets say on a SATA disk. Now, for each load / store in the application, some driver code needs to trigger that will program the SATA controller registers and do n number of thinks to initiate the diska read / write transaction. How is this achieved? Because application is not making any System calls. Its just having load / store instructions.

Thanks,

Rajat Jain
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Re: mmap confusion

am 20.09.2010 11:14:21 von m.nazarewicz

On Mon, 20 Sep 2010 07:33:05 +0200, Rajat Jain =
wrote:

> 1) If the backing file is /dev/mem or a device file, then at the time=
of mmap(),
> the page table entries / TLB entries are set up such that the virtual=
address in
> the user space, maps to the actual physical address desired. And the =
thus job
> is done. This case is clear.

Page table entries don't need to be set immediately but essentially tha=
t is the
case.

> 2) The other case is that when the file is actually a datafile presen=
t in a file
> system lets say on a SATA disk. Now, for each load / store in the app=
lication,
> some driver code needs to trigger that will program the SATA controll=
er registers
> and do n number of thinks to initiate the diska read / write transact=
ion. How is
> this achieved? Because application is not making any System calls. It=
s just having
> load / store instructions.

When a "normal" file is mapped no page entries are set. As an effect, =
when user
space refers to the mapped area a page fault is triggered. This is han=
dled by
kernel which reads a page from the disk and adds a proper page table en=
try.

On writes, such a page is marked as dirty (either CPU supports that dir=
ectly,
or kernel simulates it by setting page read-only so that on write an pa=
ge fault
is generated again). When process terminates all dirty pages are writt=
en back to
disk.

--=20
Best regards, _ _
| Humble Liege of Serenely Enlightened Majesty of o' \,=3D./ `o
| Computer Science, Michał "mina86" Nazarewicz (o o)
+----[mina86*mina86.com]---[mina86*jabber.org]----ooO--(_)-- Ooo--
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie"=
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Re: mmap confusion

am 20.09.2010 23:55:11 von Sri Ram Vemulpali

--0016364c73717170070490b7f768
Content-Type: text/plain; charset=ISO-8859-1

Hi Rajat,

mmap is used to map file(devices) or shared memory to process virtual
address.

So, for any device or file, which you want to map, everything is
treated as file. So, in all cases you are trying to avoid file system.
Typically read(),write() all these functions are generic functions provided
by filesystem for a uniform access to all devices and files hiding the
details.

So, when you are using mmap, you are excluding file system and directly
accessing memory as if it is within process address space.
Typically when you map certain virtual address of process, depending on
requested memory, those size pages are allocated to the calling process.

Now depending upon what you have mapped to, the OS is going to perform
operations on that entity for the memory addressed in store and load
instructions. This entity can be device, file stored on IDE, shared memory
segment across networks. So, this also an abstraction provided by OS. ok.

Regards,
Sri.

On Mon, Sep 20, 2010 at 1:33 AM, Rajat Jain wrote:

> Hello List,
>
> I wanted to understand how the mmap works. I mean, not from the kernel APIs
> or data structures perspective, but from the HW perspective. I understand
> that the use case is this: typically applications will mmap() a file (a
> device file or any other file) into user space, and then use direct pointers
> to read / write to that file. So as I understand, after the call to mmap,
> the compiler will generate simple load and store instructions fo any reads /
> writes into that file. What I'm trying to understand is that how is it
> ensured that those load & store instructions get translated into file reads/
> writes. I think there are two cases:
>
> 1) If the backing file is /dev/mem or a device file, then at the time of
> mmap(), the page table entries / TLB entries are set up such that the
> virtual address in the user space, maps to the actual physical address
> desired. And the thus job is done. This case is clear.
>
> 2) The other case is that when the file is actually a datafile present in a
> file system lets say on a SATA disk. Now, for each load / store in the
> application, some driver code needs to trigger that will program the SATA
> controller registers and do n number of thinks to initiate the diska read /
> write transaction. How is this achieved? Because application is not making
> any System calls. Its just having load / store instructions.
>
> Thanks,
>
> Rajat Jain
> --
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.linux-learn.org/faqs
>



--
Regards,
Sri.

--0016364c73717170070490b7f768
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi Rajat,


   =A0 =A0mmap is used to map file(devices=
) or shared memory to process virtual address.
  
=
   =A0 =A0So, for any device or file, which you want to map, everything=
is treated as file. So, in all cases you are trying to avoid file system. =
Typically read(),write() all these functions are generic functions provided=
by filesystem for a uniform access to all devices and files hiding the det=
ails.


So, when you are using mmap, you are excluding file sys=
tem and directly accessing memory as if it is within process address space.=
=A0
Typically when you map certain virtual address of process, de=
pending on requested memory, those size pages are allocated to the calling =
process.


Now depending upon what you have mapped to, the OS is g=
oing to perform operations on that entity for the memory addressed in store=
and load instructions. =A0This entity can be device, file stored on IDE, s=
hared memory segment across networks. So, this also an abstraction provided=
by OS. ok.


Regards,
Sri.

e">On Mon, Sep 20, 2010 at 1:33 AM, Rajat Jain < f=3D"mailto:rajatjain@juniper.net">rajatjain@juniper.net> wro=
te:

x #ccc solid;padding-left:1ex;">Hello List,



I wanted to understand how the mmap works. I mean, not from the kernel APIs=
or data structures perspective, but from the HW perspective. I understand =
that the use case is this: typically applications will mmap() a file (a dev=
ice file or any other file) into user space, and then use direct pointers t=
o read / write to that file. So as I understand, after the call to mmap, th=
e compiler will generate simple load and store instructions fo any reads / =
writes into that file. What I'm trying to understand is that how is it =
ensured that those load & store instructions get translated into file r=
eads/ writes. I think there are two cases:




1) If the backing file is /dev/mem or a device file, then at the time of mm=
ap(), the page table entries / TLB entries are set up such that the virtual=
address in the user space, maps to the actual physical address desired. An=
d the thus job is done. This case is clear.




2) The other case is that when the file is actually a datafile present in a=
file system lets say on a SATA disk. Now, for each load / store in the app=
lication, some driver code needs to trigger that will program the SATA cont=
roller registers and do n number of thinks to initiate the diska read / wri=
te transaction. How is this achieved? Because application is not making any=
System calls. Its just having load / store instructions.




Thanks,



Rajat Jain

--

To unsubscribe from this list: send the line "unsubscribe linux-newbie=
" in

the body of a message to major=
domo@vger.kernel.org


More majordomo info at =A0 html" target=3D"_blank">http://vger.kernel.org/majordomo-info.html

Please read the FAQ at =3D"_blank">http://www.linux-learn.org/faqs




--
Regards,
Sri=
..




--0016364c73717170070490b7f768--

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ

Re: mmap confusion

am 20.09.2010 23:57:37 von Sri Ram Vemulpali

--0016364175212a51f30490b8003a
Content-Type: text/plain; charset=ISO-8859-1

> Hi Rajat,
>
> mmap is used to map file(devices) or shared memory to process virtual
> address.
>
> So, for any device or file, which you want to map, everything is
> treated as file. So, in all cases you are trying to avoid file system.
> Typically read(),write() all these functions are generic functions provided
> by filesystem for a uniform access to all devices and files hiding the
> details.
>
> So, when you are using mmap, you are excluding file system and directly
> accessing memory as if it is within process address space.
> Typically when you map certain virtual address of process, depending on
> requested memory, those size pages are allocated to the calling process.
>
> Now depending upon what you have mapped to, the OS is going to perform
> operations on that entity for the memory addressed in store and load
> instructions. This entity can be device, file stored on IDE, shared memory
> segment across networks. So, this also an abstraction provided by OS. ok.
>
> Regards,
> Sri.
>
>
> On Mon, Sep 20, 2010 at 1:33 AM, Rajat Jain wrote:
>
>> Hello List,
>>
>> I wanted to understand how the mmap works. I mean, not from the kernel
>> APIs or data structures perspective, but from the HW perspective. I
>> understand that the use case is this: typically applications will mmap() a
>> file (a device file or any other file) into user space, and then use direct
>> pointers to read / write to that file. So as I understand, after the call to
>> mmap, the compiler will generate simple load and store instructions fo any
>> reads / writes into that file. What I'm trying to understand is that how is
>> it ensured that those load & store instructions get translated into file
>> reads/ writes. I think there are two cases:
>>
>> 1) If the backing file is /dev/mem or a device file, then at the time of
>> mmap(), the page table entries / TLB entries are set up such that the
>> virtual address in the user space, maps to the actual physical address
>> desired. And the thus job is done. This case is clear.
>>
>> 2) The other case is that when the file is actually a datafile present in
>> a file system lets say on a SATA disk. Now, for each load / store in the
>> application, some driver code needs to trigger that will program the SATA
>> controller registers and do n number of thinks to initiate the diska read /
>> write transaction. How is this achieved? Because application is not making
>> any System calls. Its just having load / store instructions.
>>
>> Thanks,
>>
>> Rajat Jain
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at http://www.linux-learn.org/faqs
>>
>
>
>
> --
> Regards,
> Sri.
>
>


--
Regards,
Sri.

--0016364175212a51f30490b8003a
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable


argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi Rajat, v>
   =A0 =A0mmap is used to map file(devices) or shared =
memory to process virtual address.

  
   =A0 =A0So, for any device or file, which you w=
ant to map, everything is treated as file. So, in all cases you are trying =
to avoid file system. Typically read(),write() all these functions are gene=
ric functions provided by filesystem for a uniform access to all devices an=
d files hiding the details.



So, when you are using mmap, you are excluding file sys=
tem and directly accessing memory as if it is within process address space.=
=A0
Typically when you map certain virtual address of process, de=
pending on requested memory, those size pages are allocated to the calling =
process.



Now depending upon what you have mapped to, the OS is g=
oing to perform operations on that entity for the memory addressed in store=
and load instructions. =A0This entity can be device, file stored on IDE, s=
hared memory segment across networks. So, this also an abstraction provided=
by OS. ok.



Regards,
Sri.
">

On Mon, Sep 20, 2010 at 1:33 AM, Rajat=
Jain < =3D"_blank">rajatjain@juniper.net> wrote:


x #ccc solid;padding-left:1ex">Hello List,



I wanted to understand how the mmap works. I mean, not from the kernel APIs=
or data structures perspective, but from the HW perspective. I understand =
that the use case is this: typically applications will mmap() a file (a dev=
ice file or any other file) into user space, and then use direct pointers t=
o read / write to that file. So as I understand, after the call to mmap, th=
e compiler will generate simple load and store instructions fo any reads / =
writes into that file. What I'm trying to understand is that how is it =
ensured that those load & store instructions get translated into file r=
eads/ writes. I think there are two cases:





1) If the backing file is /dev/mem or a device file, then at the time of mm=
ap(), the page table entries / TLB entries are set up such that the virtual=
address in the user space, maps to the actual physical address desired. An=
d the thus job is done. This case is clear.





2) The other case is that when the file is actually a datafile present in a=
file system lets say on a SATA disk. Now, for each load / store in the app=
lication, some driver code needs to trigger that will program the SATA cont=
roller registers and do n number of thinks to initiate the diska read / wri=
te transaction. How is this achieved? Because application is not making any=
System calls. Its just having load / store instructions.





Thanks,



Rajat Jain

--

To unsubscribe from this list: send the line "unsubscribe linux-newbie=
" in

the body of a message to t=3D"_blank">majordomo@vger.kernel.org

More majordomo info at =A0 html" target=3D"_blank">http://vger.kernel.org/majordomo-info.html

Please read the FAQ at =3D"_blank">http://www.linux-learn.org/faqs




--
Rega=
rds,
Sri.






--
Regards,
Sri.
=



--0016364175212a51f30490b8003a--

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ